<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-10-20
 * Time: 20:31
 */

header("charset=utf-8");


$name=$_GET["userName"];
$pass= $_GET["password"];

//1.连接数据库
$conn = mysqli_connect("localhost", "root", "","t_1014");
if($conn)
{
    //echo "hello";
}
$conn->set_charset("UTF-8");
//2.打开数据库
//mysqli_select_db($conn,"test");
//3.新建查询
//$sql = 'select * from 123 where "username"='.$name.'';#39;.$us.'and upass = '. $pass .';;

//4.执行这个查询
//$sql="SELECT * FROM abcd";
$result = mysqli_query($conn,"SELECT * FROM User WHERE userName='".$name."'");
if($result)
{
    //echo "true";
}
else
{
    die("false".mysqli_error($conn));
}
$n = mysqli_num_rows($result);

//5. 关闭数据库
mysqli_close($conn);

if($n-->0)
{
    session_start();
    $row = mysqli_fetch_array($result);
    $_SESSION['uid'] = $row["userName"];

    $usepass=$row["password"];

    if($pass==$usepass)
    {
        echo "{\"code\":1,\"message\":\"登录成功\"}";

    }
    else
        echo "登录失败";

}
else
{
    echo "登录失败";

}
?>